package alp.starcode.sanping.dataapply.controller;

import alp.starcode.common.base.annotation.operate.Add;
import alp.starcode.common.base.annotation.operate.Delete;
import alp.starcode.common.base.annotation.operate.Update;
import alp.starcode.common.mybatis.page.Pagination;
import alp.starcode.common.mybatis.sort.Sorter;
import alp.starcode.common.web.result.Result;
import alp.starcode.sanping.dataapply.model.dto.DataApplyDTO;
import alp.starcode.sanping.dataapply.model.vo.DataApplyVO;
import alp.starcode.sanping.dataapply.service.DataApplyService;
import alp.starcode.sanping.framework.base.BaseController;
import alp.starcode.sanping.framework.database.mariadb.mybatis.entity.DataApply;
import alp.starcode.sanping.information.model.vo.InformationVO;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;

/**
 * TODO
 *
 * @author wujie
 * @date 2024/3/14 17:32
 */
@Api(tags = "数据申请表")
@RestController
@RequestMapping("dataApply")
@Validated
public class DataApplyController extends BaseController {

    @Resource
    private DataApplyService dataApplyService;

    @GetMapping("pageList.do")
    @ApiOperation("数据申请表-分页查询信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searchKeyword", value = "搜索关键字", dataType = "String", paramType = "query", required = false),
    })
    @ApiOperationSupport(order = 10)
    public Result<Pagination<DataApplyVO>> pageList(Pagination<DataApply> pagination, String searchKeyword, Sorter sorters) {
        return Result.success(dataApplyService.pageList(pagination, searchKeyword, sorters));
    }

    @GetMapping("getById.do")
    @ApiOperation("数据申请表-根据ID查询信息")
    @ApiImplicitParam(name = "id", value = "流水号", dataType = "String", paramType = "query", required = false)
    @ApiOperationSupport(order = 20)
    public Result<DataApplyVO> getById(@NotEmpty(message = "流水号不能为空") String id) {
        return Result.success(dataApplyService.getById(id));
    }

    @PostMapping("add.do")
    @ApiOperation("数据申请表-添加数据")
    @ApiImplicitParams({})
    @ApiOperationSupport(order = 30)
    public Result<Object> add(@Validated(Add.class) DataApplyDTO entityDTO) {
        dataApplyService.add(entityDTO);
        return Result.success();
    }

    @PostMapping("delete.do")
    @ApiOperation("数据申请表-删除数据")
    @ApiImplicitParam(value = "流水号", name = "id", defaultValue = "1", dataType = "String", paramType = "query", required = true)
    @ApiOperationSupport(order = 40)
    public Result<Object> delete(@ApiIgnore @Validated(Delete.class) DataApplyDTO entityDTO) {
        dataApplyService.delete(entityDTO);
        return Result.success();
    }

    @PostMapping("update.do")
    @ApiOperation("数据申请表-修改数据")
    @ApiImplicitParams({})
    @ApiOperationSupport(order = 50)
    public Result<Object> update(@Validated(Update.class) DataApplyDTO entityDTO) {
        dataApplyService.update(entityDTO);
        return Result.success();
    }

}
